package com.qf.hospital.controller;

import com.qf.hospital.entity.User;
import com.qf.hospital.service.UserService;
import com.qf.hospital.vo.SideVO;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Administrator
 * @version V1.0
 * @Project hospital
 * @Package com.qf.hospital.controller
 * @Description: ${TODO}
 * @Date 2021/10/16 15:00
 */

@RestController
public class SideController {

    private Logger log = LoggerFactory.getLogger(SideController.class);

    @Autowired
    private UserService userService;

    @GetMapping("/side")
    public List<SideVO> side(){
        //1. 获取当前登录用户的id
        Subject subject = SecurityUtils.getSubject();
        User user = (User) subject.getPrincipal();
        if (user == null){
            log.info("【侧边栏】 用户登录超时！");
            return null;
        }
        Integer userId = user.getUserId();

        //2. 调用Service查询数据
        List<SideVO> result = userService.findSideByUserId(userId);

        //3.返回
        return result;
    }
}
